package pers.cz.analysis.store.excel;

import pers.cz.analysis.entitys.ClassDesc;
import pers.cz.analysis.enums.ExportConf;
import pers.cz.analysis.store.IStore;
import pers.cz.easyexcel.dao.CommonLocalFileDaoImpl;
import pers.cz.jefconfig.config.JefConfiguration;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

/**
 * @program: Jef-code-analysis
 * @description: excel存储器
 * @author: Cheng Zhi
 * @create: 2023-10-11 18:02
 **/
public class ExcelSotre implements IStore {


    @Override
    public void save(List<ClassDesc> classDescList) {

        List<ExcelClassDesc> excelClassDescs = transForm(classDescList);
        new CommonLocalFileDaoImpl(new File(JefConfiguration.get(ExportConf.JEF_ANALYSIS_SAVE_PATH))).batchInsert(excelClassDescs);

    }

    private List<ExcelClassDesc> transForm(List<ClassDesc> classDescList) {

        List<ExcelClassDesc> lists = new ArrayList<>();
        for (ClassDesc classDesc : classDescList) {
            ExcelClassDesc excelClassDesc = new ExcelClassDesc();
            excelClassDesc.setFullClassName(classDesc.getFullClassName());
            excelClassDesc.setKeyWord(classDesc.getKeyWord());
            excelClassDesc.setMethodName(classDesc.getMethodName());

            lists.add(excelClassDesc);
        }

        return lists;
    }
}
